<?php

return [
    'order'=>[
        'graph'         => 'order', // Name of the current graph - there can be many of them attached to the same object
        'property_path' => 'stateA',  // Property path of the object actually holding the state
        'states'        => [
            [ 'name'=>'checkout'],
            [ 'name'=>'pending'],
            [ 'name'=>'confirmed'],
            [ 'name'=>'cancelled']
        ],
        'transitions' => [
            'create' => [
                'from' => ['checkout'],
                'to'   => 'pending'
            ],
            'confirm' => [
                'from' => ['checkout', 'pending'],
                'to'   => 'confirmed'
            ],
            'cancel' => [
                'from' => ['confirmed'],
                'to'   => 'cancelled'
            ]
        ],
        'callbacks' => [
            'guard' => [
                'guard-cancel' => [
                    'to' => ['cancelled'], // Will be called only for transitions going to this state
                    'do' => ['MyClass', 'handle']
                ]
            ],
            'before' => [
                'from-checkout' => [
                    'from' => ['checkout'], // Will be called only for transitions coming from this state
                    'do'   => ['MyClass', 'handle']
                ]
            ],
            'after' => [
                'on-confirm' => [
                    'on' => ['confirm'], // Will be called only on this transition
                    'do' => ['MyClass', 'handle']
                ],
                'to-cancelled' => [
                    'to' => ['cancelled'], // Will be called only for transitions going to this state
                    'do' => ['MyClass', 'handle']
                ],
                'cancel-date' => [
                    'to' => ['cancelled'],
                    'do' => ['object', 'setCancelled'],
                ],
            ]
        ]
    ],
    'article' => [
        // class of your domain object
        'class' => App\Article::class,

        // name of the graph (default is "default")
        'graph' => 'article',

        // property of your object holding the actual state (default is "state")
        'property_path' => 'state',

        // list of all possible states
        'states' => [
            // a state as associative array
            ['name' => 'new'],
            // a state as associative array with metadata
            [
                'name' => 'pending_review',
                'metadata' => ['title' => 'Pending Review'],
            ],
            // states as string
            ['name' => 'awaiting_changes'],
            ['name' => 'accepted'],
            ['name' => 'published'],
            ['name' => 'rejected']    
            // 'new',
            // 'pending_review',
            // 'awaiting_changes',
            // 'accepted',
            // 'published',
            // 'rejected',
        ],

        // list of all possible transitions
        'transitions' => [
            'create' => [
                'from' => ['new'],
                'to' => 'pending_review',
            ],
            'ask_for_changes' => [
                'from' =>  ['pending_review', 'accepted'],
                'to' => 'awaiting_changes',
            ],
            'cancel_changes' => [
                'from' => ['awaiting_changes'],
                'to' => 'pending_review',
            ],
            'submit_changes' => [
                'from' => ['awaiting_changes'],
                'to' =>  'pending_review',
            ],
            'approve' => [
                'from' => ['pending_review','rejected'],
                'to' =>  'accepted',
            ],
            'publish' => [
                'from' => ['accepted'],
                'to' =>  'published',
            ],
        ],

        // list of all callbacks
        'callbacks' => [
            // will be called when testing a transition
            'guard' => [
                'guard_on_submitting' => [
                    // call the callback on a specific transition
                    'on' => 'submit_changes',
                    // will call the method of this class
                    'do' => ['MyClass', 'handle'],
                    // arguments for the callback
                    'args' => ['object'],
                ],
                'guard_on_approving' => [
                    // call the callback on a specific transition
                    'on' => 'approve',
                    // will check the ability on the gate or the class policy
                    'can' => 'approve',
                ],
            ],

            // will be called before applying a transition
            'before' => [],

            // will be called after applying a transition
            'after' => [
                'history' => [
                    'do' => 'StateHistoryManager@storeHistory',
                ],
            ],
        ],
    ],
    'post' => [
        'class' => App\Post::class,
        'graph' => 'post',

        'property_path' => 'last_state', // should exist on model

        'states' => [
            ['name' => 'draft'],
            ['name' => 'published'],
            ['name' => 'archived']
        ],
        'transitions' => [
            'publish' => [
                'from' => ['draft'],
                'to' => 'published'
            ],
            'unpublish' => [
                'from' => ['published'],
                'to' => 'draft'
            ],
            'archive' => [
                'from' => ['draft', 'published'],
                'to' => 'archived'
            ],
            'unarchive' => [
                'from' => ['archived'],
                'to' => 'draft'
            ]
        ],
        'callbacks' => [
            'after' => [
                'history' => [
                    'do' => 'StateHistoryManager@storeHistory'
                ]
            ]
        ]
    ]
];